﻿#pragma once
#include "LunarUtil.h"
#include <chrono>
#include <ctime>


class Lunar;
/// <summary>
/// 阳历日期/// 
/// </summary>
class Solar
{
public:
	/// <summary>
	/// 2000年儒略日数(2000-1-1 12:00:00 UTC)
	/// </summary>
	static const double J2000;

	/// <summary>
	/// 年
	/// </summary>
	int Year;

	/// <summary>
	/// 月
	/// </summary>
	int Month;

	/// <summary>
	/// 日
	/// </summary>
	int Day;

	/// <summary>
	/// 时
	/// </summary>
	int Hour;

	/// <summary>
	/// 分
	/// </summary>
	int Minute;

	/// <summary>
	/// 秒
	/// </summary>
	int Second;

	/// <summary>
	/// 通过年月日时分初始化
	/// </summary>
	/// <param name="year">年</param>
	/// <param name="month">月，1到12</param>
	/// <param name="day">日，1到31</param>
	/// <param name="hour">小时，0到23</param>
	/// <param name="minute">分钟，0到59</param>
	/// <param name="second">秒钟，0到59</param>
	Solar(int year, int month, int day, int hour = 0, int minute = 0, int second = 0);

	/// <summary>
	/// 默认使用当前日期初始化
	/// </summary>
	Solar();

	/// <summary>
	/// 通过日期初始化
	/// </summary>
	/// <param name="date">日期</param>
	Solar(std::time_t timestamp);

	/// <summary>
	/// 通过儒略日初始化
	/// </summary>
	/// <param name="julianDay">儒略日</param>
	Solar(double julianDay);


	/// <summary>
	/// 通过指定年月日时分获取阳历
	/// </summary>
	/// <param name="year">年</param>
	/// <param name="month">月，1到12</param>
	/// <param name="day">日，1到31</param>
	/// <param name="hour">小时，0到23</param>
	/// <param name="minute">分钟，0到59</param>
	/// <param name="second">秒钟，0到59</param>
	/// <returns>阳历</returns>
	static Solar FromYmdHms(int year, int month, int day, int hour = 0, int minute = 0, int second = 0);

	/// <summary>
	/// yyyy-MM-dd
	/// </summary>
	std::string Ymd();

	/// <summary>
	/// yyyy-MM-dd HH:mm:ss
	/// </summary>
	std::string YmdHms();

	/// <summary>
	/// 通过指定日期获取阳历
	/// </summary>
	/// <param name="date">日期</param>
	/// <returns>阳历</returns>
	static Solar FromDate(std::time_t timestamp);


	/// <summary>
	/// 通过指定儒略日获取阳历
	/// </summary>
	/// <param name="julianDay">儒略日</param>
	/// <returns>阳历</returns>
	static Solar FromJulianDay(double julianDay);

	/// <summary>
	/// 是否闰年
	/// </summary>
	bool LeapYear();

	/// <summary>
	/// 星期，0代表周日，1代表周一
	/// </summary>
	int Week();

	/// <summary>
	/// 儒略日
	/// </summary>
	double JulianDay();



	/// <summary>
	/// 通过八字获取阳历列表
	/// </summary>
	/// <param name="yearGanZhi">年柱</param>
	/// <param name="monthGanZhi">月柱</param>
	/// <param name="dayGanZhi">日柱</param>
	/// <param name="timeGanZhi">时柱</param>
	/// <param name="sect">流派，2晚子时日柱按当天，1晚子时日柱按明天</param>
	/// <param name="baseYear">起始年</param>
	/// <returns>符合的阳历列表</returns>
	static std::vector<Solar>* FromBaZi(std::string& yearGanZhi, std::string& monthGanZhi, std::string& dayGanZhi, std::string& timeGanZhi,
		int sect = 2, int baseYear = 1900);

	/// <summary>
	/// 阴历
	/// </summary>
	Lunar lunar();


	/// <summary>
	/// 阳历日期相减，获得相差天数
	/// </summary>
	/// <param name="solar">阳历</param>
	/// <returns>天数</returns>
	int Subtract(Solar& solar);

	/// <summary>
	/// 获取往后推几天的阳历日期，如果要往前推，则天数用负数
	/// </summary>
	/// <param name="days">天数</param>
	/// <param name="onlyWorkday">是否仅工作日</param>
	/// <returns>阳历日期</returns>
	Solar Next(int days, bool onlyWorkday = false);


	/// <summary>
	/// 日推移
	/// </summary>
	/// <param name="days">天数</param>
	/// <returns>阳历</returns>
	Solar NextDay(int days);



};

